package com.yms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yms.mapper.HostMapper;
import com.yms.pojo.Host;
import com.yms.pojo.HostCondition;
import com.yms.pojo.PageResult;
import com.yms.service.IHostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-03-20
 */
@Service
public class HostServiceImpl extends ServiceImpl<HostMapper, Host> implements IHostService {
    //声明mapper层属性
    @Autowired
    private HostMapper hostMapper;
    //分页加载主持人信息
    @Override
    public PageResult<Host> selHostInfoService(Integer page, Integer rows, HostCondition hostCondition) {
        //1.创建分页对象存储分页条件
            IPage<Host> p=new Page<>(page,rows);
        //2.调用mapper层完成查询
            IPage<Host> phost=hostMapper.selHostInfoMapper(p,hostCondition);
        //3.将结果封装PageResult并返回
                PageResult<Host> pageResult=new PageResult<>();
                pageResult.setTotal(phost.getTotal());
                pageResult.setRows(phost.getRecords());
        //4.返回结果
        return pageResult;
    }

    @Override
    public List<Host> selHostMore(HostCondition hostCondition) {
            return  hostMapper.selectMore(hostCondition);
    }

    @Override
    public List<Host> selectAll() {
        List<Host> hostList = hostMapper.selectList(null);
        return hostList;
    }
}
